import React, {Component} from 'react';
import {
  View,
  TouchableOpacity,
  Text,
  Image,
} from 'react-native';

import Config from '../../config';
import TImage from '../../components/TImage';
import CommonListPage from '../common/CommonListPage';
import SizeUtils from '../../common/SizeUtils';
import Constants from '../../common/Constants';
import RequestNewsPostsAction from '../../actions/news/RequestNewsPostsAction';

export default class NewsTopicsPage extends CommonListPage {
    constructor(props) {
      super(props);

      this._noEmpty = true;
      this._dataKey = "news_id";
    }

    _getListViewStyle() {
      return {
          width:SizeUtils.getWindowSize().width,
          height:(SizeUtils.getWindowSize().height - Config.paddingTop - SizeUtils.translateDesignHeightToCode(30)),
          backgroundColor:"#ffffff"};
    }

    _requestData(page, listView) {
      let linkArr = this.props.pageData.routeData.topicData ? this.props.pageData.routeData.topicData.link.split(";") : [];
      if(linkArr.length > 1) {
          new RequestNewsPostsAction().call(listView, {page:page, tag:0, topics:[linkArr[1]]})
      }
    }

    _onPressItem(data) {
      this.gotoPage(Config.pages.news_content, data);
    }

    _onRenderHeader() {
      return(
        <View style={{paddingTop:SizeUtils.translateDesignHeightToCode(20),
            paddingLeft:SizeUtils.translateDesignWidthToCode(40), paddingRight:SizeUtils.translateDesignWidthToCode(40),
            paddingBottom:SizeUtils.translateDesignHeightToCode(42), flexDirection:"column",
            alignItems:"center"}}>
          <TImage style={{width:670, height:300}} source={{uri:this.props.pageData.routeData.topicData ? this.props.pageData.routeData.topicData.image_url : ""}}/>
          <Text style={{color:"#666666", fontSize:SizeUtils.translateFontSizeToCode(26),
              paddingTop:SizeUtils.translateDesignHeightToCode(30),
              lineHeight:SizeUtils.translateDesignHeightToCode(50)}}>
            新闻专题始料所及减肥啦就是当减肥了啊爽阿里飞机阿拉斯加到了放假姐啊爽了江东父老卡时间啊爽点击付款就撒了试试
          </Text>
        </View>
      )
    }

    _onRenderItem(data) {
      return (
        <Item data={data} />
      );
    }
}

import BaseItem from '../common/BaseItem';
import {DateUtils} from '../../utils/Utils';

export class Item extends BaseItem {
  constructor(props) {
    super(props);
  }

  render() {
    return (
      <View style={{width:SizeUtils.getWindowSize().width - SizeUtils.translateDesignWidthToCode(80),
          marginLeft:SizeUtils.translateDesignWidthToCode(40),
          marginRight:SizeUtils.translateDesignWidthToCode(40),
          paddingTop:SizeUtils.translateDesignHeightToCode(40),
          paddingBottom:SizeUtils.translateDesignHeightToCode(40), flexDirection:"row",
          borderTopWidth:SizeUtils.translateDesignNumToCode(3),
          borderBottomWidth:SizeUtils.translateDesignNumToCode(3),
          borderColor:"#eeeeee"}}>
          {this._renderOneImage()}
          <View style={{flex:1, paddingLeft:SizeUtils.translateDesignWidthToCode(20),}}>
            <Text style={{fontSize:SizeUtils.translateFontSizeToCode(32), color:"#000000",
                fontWeight:"bold", }} numberOfLines={1}>
              {this.props.data.title}
            </Text>
            <View style={{flexDirection:"row",
                marginTop:SizeUtils.translateDesignHeightToCode(40)}}>
              <Text style={{fontSize:SizeUtils.translateFontSizeToCode(26), color:"#999999",}}>
                {this._getDateSource(this.props.data) + " " +
                  DateUtils.formatDate2(this.props.data.posted_at, false) + " 浏览:" +
                  this.props.data.readers_num}
              </Text>
            </View>
          </View>
      </View>
    )
  }

  _renderOneImage() {
    if(this.props.data.image_urls && this.props.data.image_urls.length > 0) {
      return (
        <TImage source={{uri:this.props.data.image_urls[0]}} style={{width:200, height:120}}
          isMini={true} miniSize={"mini500"} />
      )
    }
    else {
      return (
        <TImage source={require("../../../resource/images/common/wutu.png")} style={{width:200, height:120}} />
      )
    }
  }

  _getDateSource(data) {
    if(data.source) {
      return "来自:" + data.source;
    }
    return "";
  }
}
